/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef VIEW_WINDOW_H_INCLUDED
#define VIEW_WINDOW_H_INCLUDED

#include "gl_window.h"
#include "managed_window.h"
#include "free_camera.h"
#include "property_manager.h"
#include "axis.h"
#include "mesh.h"

class ViewWindow : public GLWindow, public ManagedWindow
{
private:
    bool m_mouseCaptured;
    FreeCamera m_camera;
    Axis m_axis;
    Mesh* mesh;

    bool forward, backward, left, right, up, down;
    bool wireframe;
public:
    void loadMesh();

    template<class Archive> ViewWindow(wxWindow* parent, Archive *ar) : GLWindow(parent, wxDefaultPosition, wxDefaultSize), m_axis(&m_camera)
    {
        m_mouseCaptured = false; wireframe = false;
    }

    void init();

    template<class Archive> static ManagedWindow* createWindow(wxWindow* parent, Archive *ar)
    {
        ViewWindow* wnd = new ViewWindow(parent, ar);
        return wnd;
    }

    ManagedWindow* clone(wxWindow* parent)
    {
        return createWindow<void>(parent, NULL);
    }

    wxWindow* getWindow()
    {
        return this;
    }

    std::string getName()
    {
        return "ViewWindow";
    }

    template<class Archive> void saveWindow( Archive* ar)
    {
    }

    void scanKeys();

    void onKeyDown(wxKeyEvent &event);
    void onMouseEvent(wxMouseEvent &event);
    void onMouseMove(wxMouseEvent &event);

    virtual void update(int interval);
    void reshape(int x, int y, int width, int height);

    DECLARE_EVENT_TABLE()

};

#endif // VIEW_WINDOW_H_INCLUDED
